package com.example.day002;

import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.view.Window;
import android.view.WindowManager;

public class ForceOfflineReceive extends BroadcastReceiver {

	public void onReceive(final Context context, Intent intent) {
		AlertDialog.Builder builder = new Builder(context);
		builder.setTitle("waring");
		builder.setMessage("你被强制下线，请重新登陆");
		builder.setCancelable(false);
		builder.setPositiveButton("OK", new OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				ActivityCollector.finishAll();
				Intent intent = new Intent(context,LoginActivity.class);
				intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
				context.startActivity(intent);
			}
		});
		AlertDialog alertDialog = builder.create();
		//设置AlsertDialog的类型，确保可以在receive中正常弹出
		alertDialog.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT);
		alertDialog.show();
	}
}